<template>
	<view class="container">
		<view class="status_bar">
			<view style="margin-left: 4%;" @tap="goBack()"><u-icon name="arrow-leftward" size='24' /></view>
			<view style="margin-left: -50upx; font-weight: bold;">群公告</view>
			<view></view>
			</u-icon>
		</view>
		<view class="scroll-view-box" style="width: 90%;margin: 0 auto;">
			<u--textarea v-model="info.g_notice" placeholder="请输入公告"></u--textarea>
		</view>
		<u-button @click="addmsg" style="width: 90%;margin: 10px auto;" type="primary" text="确定"></u-button>
	</view>
</template>trash

<script>
	export default {
		data() {
			return {
				newnotice: '',
				userId: uni.getStorageSync('userId') || '',
				startX: 0, // 触摸开始的X坐标
				endX: 0, // 触摸结束的X坐标
				threshold: 50, // 设置滑动多少距离后触发返回  
				hasMore: true, // 是否有更多数据
				info: ''
			}
		},
		onLoad(options) {

			this.info = JSON.parse(options.groupId)
			console.log(this.info)
		},
		onReachBottom() {
			if (this.hasMore) {
				this.loadMore(); // 调用加载更多方法
			}
		},
		onPullDownRefresh() {
			this.refreshData(); // 调用刷新数据方法
		},
		mounted() {
			this.loadMore(); // 初始化时加载数据
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			addmsg() {
				if (this.info.g_owner_user_uid != uni.getStorageSync('userId')) {
					this.$util.toast('不是群主不能修改');
					return
				}
				const newDataObj = {
					"g_notice": this.info.g_notice, // 新的公告
					"g_notice_updateuid": uni.getStorageSync('user_uid'), // 本次公告修改人
					"g_id": this.info.g_id
				};
				const newDataJsonStr = JSON.stringify(newDataObj)
				const requestData = {
					"processorId": '1016',
					"jobDispatchId": '24',
					"actionId": '22',
					"newData": newDataJsonStr,


				};
				const requestDataJsonStr = JSON.stringify(requestData);
				uni.request({
					url: 'http://chat.zwsmcn.com:8090/rest_post',
					header: {
						'content-type': 'application/json'
					},
					data: requestDataJsonStr,
					method: 'POST',
					success: res => {
						uni.navigateBack({
							delta: 1
						});
					},
					fail: res => {
						console.log(res);
					}
				});
			},

			// 加载更多数据
			loadMore() {
				if (this.hasMore) {
					// 模拟加载数据
					setTimeout(() => {
						for (let i = 0; i < this.pageSize; i++) {
							this.list.push(`Item ${(this.page - 1) * this.pageSize + i}`);
						}
						this.page++;
						// 模拟数据加载完毕，可以在这里判断是否还有更多数据
						if (this.list.length > 2) {
							this.hasMore = true;
						} else {
							this.hasMore = false;
						}
					}, 1000);
				}
			},
			// 刷新数据
			refreshData() {
				// 模拟数据刷新
				setTimeout(() => {
					this.list = []; // 清空原有数据
					this.page = 1; // 重置页数
					this.loadMore(); // 加载新的数据
					uni.stopPullDownRefresh(); // 停止下拉刷新动作
				}, 1000);
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		overflow: hidden;
	}

	.container {
		width: 100%;
		height: 100%;

	}

	.status_bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 50upx;
	}

	.status_bar,
	.head {
		background-color: #fff;
		height: 160upx;
	}

	.shop-box {
		width: 92%;
		margin-left: 4%;
		background-color: #fff;
		margin-top: 20upx;
		border-radius: 20upx;
		padding: 10upx 30upx;

		color: #2e2e2e;
		font-weight: 300;
		display: flex;
		justify-content: space-between;
		align-items: center;

	}

	.name-img {
		width: 120upx;
		height: 120upx;
		border-radius: 10upx;
		background: #d54827;
		font-size: 36upx;
		text-align: center;
		line-height: 120upx;
		color: #fff;
		margin-left: 10upx;
	}
</style>